package com.atguigu.demojuc.chap05;

import java.util.concurrent.TimeUnit;

/**
 * @author njg
 * @version 1.0
 * @date 2025/6/17 15:40
 */
public class JoinDemo {
    public static void main(String[] args) throws InterruptedException {
        Runnable runnable = new Runnable() {
            public void run() {
                System.out.println(Thread.currentThread().getName() + "\t" + "进入教室开始学习");
                try {
                    TimeUnit.SECONDS.sleep(3);
                    System.out.println(Thread.currentThread().getName() + "\t" + "学习完毕，离开教室");
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
        };
        Thread thread1 = new Thread(runnable,"同学1");
        Thread thread2 = new Thread(runnable,"同学2");
        Thread thread3 = new Thread(runnable,"同学3");
        Thread thread4 = new Thread(runnable,"同学4");
        Thread thread5 = new Thread(runnable,"同学5");
        Thread thread6 = new Thread(runnable,"同学6");

        thread1.start();
        thread2.start();
        thread3.start();
        thread4.start();
        thread5.start();
        thread6.start();


        thread1.join();
        thread2.join();
        thread3.join();
        thread4.join();
        thread5.join();
        thread6.join();

        Thread.currentThread().setName("班长");
        System.out.println(Thread.currentThread().getName() + "\t" + "所有同学离开完毕，锁门");

    }
}
